package com.flower.service.impl;

import com.flower.mapper.BuyMapper;
import com.flower.model.dto.BuyPageQueryDTO;
import com.flower.model.entity.Buy;
import com.flower.result.PageResult;
import com.flower.service.BuyService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName BuyServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/16 23:03
 *@Version 1.0
 */
@Service
public class BuyServiceImpl implements BuyService {
    @Autowired
    private BuyMapper buyMapper;
    @Override
    public PageResult pageQuery(BuyPageQueryDTO buyPageQueryDTO) {
        PageHelper.startPage(buyPageQueryDTO.getPageNum(), buyPageQueryDTO.getPageSize());
        Page<Buy> page = buyMapper.pageQuery(buyPageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void addOrUpdate(Buy buy) {
        if (buy.getId() == null) {
            buyMapper.add(buy);
        } else {
            buyMapper.update(buy);
        }
    }

    @Override
    public void deleteBuy(Integer id) {
        buyMapper.deleteBuyById(id);
    }

    @Override
    public void deleteBuyBatch(List<Integer> ids) {
        ids.forEach(id -> buyMapper.deleteBuyById(id));
    }

    @Override
    public PageResult findPage1(Page<Object> objects) {
        PageHelper.startPage(objects.getPageNum(), objects.getPageSize());
        Page<Buy> page = buyMapper.findpage1(objects);
          return new PageResult(page.getTotal(), page.getResult());
    }
}
